home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / exec / makefunctions.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  3KB  |  127 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: makefunctions.c,v 1.7 1996/10/24 15:50:51 aros Exp $
  4.     $Log: makefunctions.c,v $
  5.     Revision 1.7  1996/10/24 15:50:51  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.6  1996/10/23 14:28:53  aros
  9.     Use the respective macros to access and manipulate a libraries' jumptable
  10.  
  11.     Revision 1.5  1996/10/19 17:07:26  aros
  12.     Include <aros/machine.h> instead of machine.h
  13.  
  14.     Revision 1.4  1996/08/13 13:56:03  digulla
  15.     Replaced AROS_LA by AROS_LHA
  16.     Replaced some AROS_LH*I by AROS_LH*
  17.     Sorted and added includes
  18.  
  19.     Revision 1.3  1996/08/01 17:41:13  digulla
  20.     Added standard header for all files
  21.  
  22.     Desc:
  23.     Lang: english
  24. */
  25. #include <exec/execbase.h>
  26. #include <aros/libcall.h>
  27. #include <aros/machine.h>
  28.  
  29. /*****************************************************************************
  30.  
  31.     NAME */
  32.     #include <clib/exec_protos.h>
  33.  
  34.     AROS_LH3(ULONG, MakeFunctions,
  35.  
  36. /*  SYNOPSIS */
  37.     AROS_LHA(APTR, target,        A0),
  38.     AROS_LHA(APTR, functionArray, A1),
  39.     AROS_LHA(APTR, funcDispBase,  A2),
  40.  
  41. /*  LOCATION */
  42.     struct ExecBase *, SysBase, 15, Exec)
  43.  
  44. /*  FUNCTION
  45.     Creates the jumptable for a shared library and flushes the processor's
  46.     instruction cache. Does not checksum the library.
  47.  
  48.     INPUTS
  49.     target          - The highest byte +1 of the jumptable. Typically
  50.             this is the library's base address.
  51.     functionArray - Pointer to either an array of function pointers or
  52.             an array of WORD displacements to a given location
  53.             in memory. A value of -1 terminates the array in both
  54.             cases.
  55.     funcDispBase  - The base location for WORD displacements or NULL
  56.             for function pointers.
  57.  
  58.     RESULT
  59.     Size of the jumptable.
  60.  
  61.     NOTES
  62.  
  63.     EXAMPLE
  64.  
  65.     BUGS
  66.  
  67.     SEE ALSO
  68.  
  69.     INTERNALS
  70.  
  71.     HISTORY
  72.  
  73. ******************************************************************************/
  74. {
  75.     AROS_LIBFUNC_INIT
  76.     long n;
  77.     APTR lastvec;
  78.  
  79.     n = 1;
  80.  
  81.     if (funcDispBase!=NULL)
  82.     {
  83.     /* If FuncDispBase is non-NULL it's an array of relative offsets */
  84.     WORD *fp=(WORD *)functionArray;
  85.  
  86.     /* -1 terminates the array */
  87.     while(*fp!=-1)
  88.     {
  89.         /* Decrement vector pointer by one and install vector */
  90.         __AROS_INITVEC(target,n);
  91.         __AROS_SETVECADDR(target,n,funcDispBase+*fp);
  92.  
  93.         /* Use next array entry */
  94.         fp++;
  95.         n++;
  96.     }
  97.     }
  98.     else
  99.     {
  100.     /* If FuncDispBase is NULL it's an array of function pointers */
  101.     void **fp=(void **)functionArray;
  102.  
  103.     /* -1 terminates the array */
  104.     while(*fp!=(void *)-1)
  105.     {
  106.         /* Decrement vector pointer by one and install vector */
  107.         __AROS_INITVEC(target,n);
  108.         __AROS_SETVECADDR(target,n,*fp);
  109.  
  110.         /* Use next array entry */
  111.         fp++;
  112.         n++;
  113.     }
  114.     }
  115.  
  116.     lastvec = __AROS_GETJUMPVEC(target,n);
  117.     n = (IPTR)funcDispBase-(IPTR)lastvec;
  118.  
  119.     /* Clear instruction cache for the whole jumptable */
  120.     CacheClearE(lastvec, n, CACRF_ClearI);
  121.  
  122.     /* Return size of jumptable */
  123.     return n;
  124.     AROS_LIBFUNC_EXIT
  125. } /* MakeFunctions */
  126.  
  127.